package com.neusoft.demosb.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.neusoft.demosb.entity.Lab;
import com.neusoft.demosb.service.LabService;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wenchang
 * @Description //TODO
 * @Date 16:23 2020/6/04
 */
public class LabExcelLisener extends AnalysisEventListener<Lab> {
    private List<Lab> data = new ArrayList<>();

    private LabService labService;

    public LabExcelLisener(LabService labService) {
        this.labService = labService;
    }

    @Override
    public void invoke(Lab labExcel, AnalysisContext analysisContext) {
        //解析数据保存到labExcel
        data.add(labExcel);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //当Excel解析完毕后，执行
        System.out.println(data);
        if (labService != null) {
            labService.insert(data);
        }
    }
}
